package com.example.job;

import com.example.service.DocService;
import com.example.service.EbookSnapshotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class EbookSnapshotJob {

    @Autowired
    EbookSnapshotService ebookSnapshotService;

    /**
     * 自定义cron表达式
     * 只有等上一次执行完成，下一次才会在下一个时间点执行，错过就错过
     */
    @Scheduled(cron = "5/30 * * * * ?")
    public void cron() throws InterruptedException {
        long start = System.currentTimeMillis();
        ebookSnapshotService.getEbookSnapshot();
        System.out.println("EbookSnapshotJob从第5秒开始，每隔30秒钟执行一次： "+ (System.currentTimeMillis()-start));
    }
}
